﻿/*
 * @Autor: PK
 * @Date: 2022/01/15 09:26:SS
 */

using System;
using System.Collections.Generic;
using System.Linq;
using ShkSimulation.carsharing;
using ShkSimulation.core.template;
using ShkSimulation.core.template.agency;
using ShkSimulation.core.template.customer;

namespace ShkSimulation.carsharing.efficiency {

	public class EvaluationDemandManager: LambdaDemandManager {

		public EvaluationDemandManager() : base(CreateTemplate) {
		}

		public static double DayArriveCount = 1200;
		
		public static TimeSpan ArriveSpan => TimeSpan.FromDays(1 / DayArriveCount);

		private static List<CustomerTemplate> CreateTemplate(NetworkInputData inputData) {
			//TODO 存在顺序问题，需要制定工厂创建顺序！
			Dictionary<int, Agency> stations = inputData.ClassifiedAgencies[CarsharingConfig.StationResourceKey].ToDictionary(each => each.UniqueId, each => each);
			List<Agency> roads = inputData.ClassifiedAgencies[CarsharingConfig.RoadResourceKey];
			List<CustomerTemplate> result = new List<CustomerTemplate>();
			foreach (Agency abstractRoad in roads) {
				EvaluationRoad road = abstractRoad as EvaluationRoad;
				List<Agency> agencies = new List<Agency>();
				agencies.Add(stations[road.LastStation]);
				agencies.Add(road);
				agencies.Add(stations[road.NextStation]);
				string uniqueKey = $"{road.LastStation}-{road.NextStation}";
				result.Add(new EvaluationTemplate(uniqueKey, agencies, ArriveSpan));
			}
			return result;
		}


	}

}